<template>
	<view class="search-page">
		<u-navbar title="高级筛选" :autoBack="true" :placeholder="true"> </u-navbar>
		<view class="search-box">
			<!-- <view class="search-item">
				<view class="item-top">
					<view class="top-left">
						<view class="dot"></view>距离
					</view>
					<view class="top-right" v-if="searchData.distance">{{searchData.distance}}km</view>
				</view>
				<view class="item-bottom">
					<u-slider v-model="searchData.distance" max="100" activeColor="#F169F6"></u-slider>
				</view>
			</view> -->
			<view class="search-item">
				<view class="item-top">
					<view class="top-left">
						<view class="dot"></view>年龄
					</view>
					<view class="top-right" v-if="searchData.age">{{searchData.age}}</view>
				</view>
				<view class="item-bottom">
					<view class="select-list">
						<view :class="searchData.age==item?'select-item active':'select-item'" v-for="(item,index) in ageList" :key="index" @click="selectSearch('age',item)">
							{{item}}
						</view>
					</view>
				</view>
			</view>
			<view class="search-item">
				<view class="item-top">
					<view class="top-left">
						<view class="dot"></view>相似度
					</view>
					<view class="top-right"></view>
				</view>
				<view class="item-bottom">
					<view class="select-list">
						<view :class="searchData.head_xsd==item?'select-item active':'select-item'" v-for="(item,index) in headXsdList" :key="index" @click="selectSearch('head_xsd',item)">
							{{item}}
						</view>
					</view>
				</view>
			</view>
			<view class="search-item">
				<view class="item-top">
					<view class="top-left">
						<view class="dot"></view>职业
					</view>
					<view class="top-right"></view>
				</view>
				<view class="item-bottom">
					<view class="select-list">
						<view :class="searchData.work==item?'select-item active':'select-item'" v-for="(item,index) in workList" :key="index" @click="selectSearch('work',item)">
							{{item}}
						</view>
					</view>
				</view>
			</view>
			<!-- <view class="search-item">
				<view class="item-top">
					<view class="top-left">
						<view class="dot"></view>活跃状态
					</view>
					<view class="top-right"></view>
				</view>
				<view class="item-bottom">
					<view class="select-list">
						<view :class="searchData.hy_status==item.value?'select-item active':'select-item'"
							v-for="(item,index) in statusList" :key="index" @click="selectSearch('status',item)">
							{{item.label}}
						</view>
					</view>
				</view>
			</view> -->
		</view>
		<view class="button-group">
			<view class="button1" @click="confirmSelect">确定</view>
		</view>
		<view class="reload-bxo" @click="reloadSelect">
			<u-icon name="reload" size="16" color="#9451F3"></u-icon>
			<text style="margin: 0 10rpx;">恢复默认设置</text>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				oldSearchData: {},
				searchData: {
					// distance: 10,
					distance: '',
					age: '',
					head_xsd: '',
					// hy_status: '',
					work: ''
				},
				ageList: ['18-30', '31-40', '41-50'],
				headXsdList: ['70', '80', '90'],
				workList: ['影视/娱乐', '文化/艺术', '金融/投资', 'IT/互联网', '健身/美容', '媒体/公关', '商业/零售', '工业/制造业', '教育/科研', '自由职业者', '模特', '学生', '其他'],
				statusList: [{
					label: '在线',
					value: 1
				}, {
					label: '离线',
					value: 2
				}, {
					label: '最近活跃',
					value: 3
				}, {
					label: '一周内活跃',
					value: 4
				}, ],
			}
		},
		onLoad() {
			let searchData = uni.getStorageSync('searchData') || {}
			this.searchData = searchData
		},
		methods: {
			reloadSelect() {
				this.searchData = {
					city_id: this.searchData.city_id,
					city_name: this.searchData.city_name,
					age: '',
					head_xsd: '',
					work: ''
				}
				uni.setStorageSync('searchData', this.searchData)
				this.$Toast('恢复默认设置成功')
			},
			confirmSelect() {
				uni.setStorageSync('searchData', this.searchData)
				this.$Toast('设置成功')
				uni.navigateBack({
					delta: 1
				})
			},
			selectSearch(type, item) {
				if (type == 'age') {
					this.searchData.age = item
				}
				if (type == 'head_xsd') {
					this.searchData.head_xsd = item
				}
				if (type == 'work') {
					this.searchData.work = item
				}
				if (type == 'status') {
					this.searchData.hy_status = item.value
					// const indexInArray = this.searchData.status.indexOf(item);
					// if (indexInArray > -1) {
					// 	// 如果索引在数组中，则移除它
					// 	this.searchData.status.splice(indexInArray, 1);
					// } else {
					// 	// 如果索引不在数组中，则添加它
					// 	this.searchData.status.push(item)
					// }
				}
			}
		}
	}
</script>
<style lang="scss" scoped>
	.search-page {
		width: 100%;
		min-height: 100vh;
		position: relative;
		background-color: #F8F8F8;

		.search-box {
			padding: 20rpx;

			.search-item {
				padding: 30rpx;
				background: linear-gradient(180deg, #FFDAF5 0%, #FFFFFF 10%);
				box-shadow: 0rpx 4rpx 32rpx 0rpx #FFF0FD;
				border-radius: 32rpx;
				border: 2rpx solid;
				border-image: linear-gradient(180deg, rgba(255, 255, 255, 1), rgba(255, 255, 255, 1)) 2 2;
				margin-bottom: 20rpx;

				.item-top {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.top-left,
					.top-right {
						display: flex;
						align-items: center;

						.dot {
							width: 12rpx;
							height: 12rpx;
							background: #F169F6;
							border-radius: 50%;
							margin-right: 10rpx;
						}
					}

					.top-left {
						font-weight: 600;
						font-size: 32rpx;
					}

					.top-right {
						font-size: 32rpx;
						color: #F169F6;
					}
				}

				.item-bottom {
					margin-top: 42rpx;

					.select-list {
						display: grid;
						grid-template-columns: repeat(3, 1fr);
						grid-auto-flow: row;
						grid-gap: 20rpx;

						.select-item {
							width: 192rpx;
							height: 64rpx;
							background-color: #f6f6f6;
							line-height: 64rpx;
							text-align: center;
							border-radius: 32rpx;
							border: 1px solid #f6f6f6;
						}

						.active {
							color: #F169F6;
							border: 1px solid #F169F6;
							background-color: #ffe9fc;
						}
					}
				}
			}
		}

		.reload-bxo {
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			color: #9451F3;
			padding-bottom: 40rpx;
		}

		.button-group {
			padding-bottom: 20rpx;

			.button1 {
				margin: 100rpx auto 0;
				width: 694rpx;
				height: 88rpx;
				font-weight: bold;
				font-size: 30rpx;
				color: #FFFFFF;
				text-align: center;
				line-height: 88rpx;
				background: linear-gradient(135deg, #FE93BF 0%, #A27AFF 100%);
				border-radius: 20rpx 20rpx 20rpx 20rpx;
			}
		}
	}
</style>